package com.lkd.controller;


import com.lkd.entity.User;
import com.lkd.service.UserService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import com.lkd.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 聂德祥
 * @since 2024-08-17
 */
@RestController
public class UserController {
@Autowired
    private UserService userService;
@GetMapping("/api/user-service/user/search")
    public Result search(String userName, @RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize){

       PageBean<UserVo> page = userService.search(userName,pageIndex,pageSize);
            return Result.success(page);
}
//新增人员
    @PostMapping("/api/user-service/user")
    public Result add(@RequestBody User user){
        userService.save(user);
        return Result.success();
    }
    // 修改人员
    @PutMapping("/api/user-service/user")
    public Result update(@RequestBody User user){
        userService.updateById(user);
        return Result.success();
    }
    // 删除人员
    @DeleteMapping("/api/user-service/user/{id}")
    public Result delete(@PathVariable Integer id){
        userService.removeById(id);
        return Result.success();
    }
}
